package piano;

/*
 * Modified Version
 * Author: rendy.jr
 * Date: Jun 10, 2011
 * 6.005 Elements of Software Construction
 * Rendy Bambang Junior
 * rendy.jr@gmail.com
 *  
 * Responsible for
 * - play the pitch
 * - cycle instrument 
 *  
 */


import javax.sound.midi.MidiUnavailableException;

import midi.Instrument;
import midi.Midi;
import music.Pitch;

public class Piano {
	private Instrument inst = Instrument.PIANO;
	Midi midi;
	
	public Piano(){
		try {
			midi = new Midi();
		} catch (MidiUnavailableException e1) {
			e1.printStackTrace();
			return;
		}
	}
	
	public void nextInstrument(){
		inst = inst.next();
	}
	
	public void play(char key){
		midi.beginNote(new Pitch(key).toMidiFrequency(),inst);
	}
	
	public void stop(char key){
		midi.endNote(new Pitch(key).toMidiFrequency(),inst);
	}
}
